package gdut.imis.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import gdut.imis.Utils.Result;
import gdut.imis.domain.ClubInstitutionFile;
import gdut.imis.enums.Status;
import gdut.imis.mapper.ClubInstitutionFileMapper;
import gdut.imis.service.ClubInstitutionFileService;
import gdut.imis.vo.ClubInstitutionFileVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description
 * @Author JiaFu
 * @Date 2023/4/7 15:23
 */
@Service
@RequiredArgsConstructor
public class ClubInstitutionFileServiceImpl extends ServiceImpl<ClubInstitutionFileMapper, ClubInstitutionFile> implements ClubInstitutionFileService {

    private final ClubInstitutionFileMapper clubInstitutionFileMapper;
    /***
     * 新增社团机构档案
     * @param: clubInstitutionFile
     * @return Result
     */
    @Override
    public Result addClubInstitution(ClubInstitutionFile clubInstitutionFile) {
        if (Objects.isNull(clubInstitutionFile)) {
            return Result.errorWithArgs(Status.REQUEST_PARAMS_NOT_VALID_ERROR, "clubInstitution");
        }
        boolean flag = this.save(clubInstitutionFile);
        if (flag) {
            return Result.success();
        }
        return Result.errorWithArgs(Status.FAILED, "新增社团机构档案失败");
    }

    /***
     * 根据学生id查询学生第一次加入社团的档案回忆
     * @param: studentId
     * @return Result
     */
    @Override
    public Result getClubInstitutionMemoryByStuId(Long studentId) {
        ClubInstitutionFileVo clubInstitutionFileVo = clubInstitutionFileMapper.getClubInstitutionMemoryByStuId(studentId);
        if (Objects.isNull(clubInstitutionFileVo)) {
            return Result.errorWithArgs(Status.FAILED,"没有查询到该学生的社团档案回忆");
        }
        return Result.success(clubInstitutionFileVo);
    }
}
